function getPosition(a, b) {
    for (var c = 0; c < b.length; c++) if (a == b[c]) return c;
}

var parentTopHeight, broswerFlag, selectTree_id;

jQuery.fn.extend({
    selectCustomRender: function() {
        var a = $(this).html();
        return this.each(function() {
            $(this).empty(), new jQuery.SelectCustomBox(this, a);
        });
    },
    selectCustomSetValue: function(a, b) {
        var d, f, g, c = uncompile(quiLanguage.selectCustom.promptMessage);
        if (null != $(this).attr("prompt") && (c = $(this).attr("prompt")), $(this).find("input").each(function() {
            ("selectbox error-field" == $(this).attr("class") || "selectbox" == $(this).attr("class")) && (d = $(this));
        }), "" == a) {
            if (d.val(c), "true" == $(this).attr("multiMode") || 1 == $(this).attr("multiMode")) {
                d.attr("title", " ");
                try {
                    addTooltip(d[0]);
                } catch (e) {}
            }
            return $(this).attr("relValue", ""), $(this).attr("relText", ""), $(this).attr("editValue", ""), 
            void 0;
        }
        if (d.val(b), $(this).attr("relValue", a), $(this).attr("editValue", a), $(this).attr("relText", b), 
        f = $(this).attr("name"), f && $(this).find("input:hidden").each(function() {
            $(this).attr("name") == f && $(this).val(a);
        }), "true" == $(this).attr("multiMode") || 1 == $(this).attr("multiMode")) {
            d.attr("title", b);
            try {
                addTooltip(d[0]);
            } catch (e) {}
        } else g = $(this).find("div[class=selectbox-tree]"), g.attr("hasfocus", 0), g.hide(), 
        $(this).trigger("boxClose");
    },
    selectCustomClose: function() {
        var a = $(this).find("div[class=selectbox-tree]");
        a.attr("hasfocus", 0), a.hide(), $(this).trigger("boxClose");
    }
}), selectTree_id = 1, jQuery.SelectCustomBox = function(a, b) {
    function x() {
        var a, b, c;
        o.css({
            overflowY: "visible",
            overflowX: "visible"
        }), o.width(""), o.height(""), a = 200, a = window.document.documentElement.clientHeight - (i.offset().top - $(window).scrollTop()) - 30, 
        i.attr("boxWidth") || (b = o.width()), o.css({
            overflowY: "auto",
            overflowX: "hidden"
        }), i.attr("boxWidth") ? o.width(Number(i.attr("boxWidth"))) : o.width(b), c = 0, 
        i.attr("boxHeight") && (c = Number(i.attr("boxHeight"))), 0 != c ? (o.height(c), 
        "top" == i.attr("openDirection") ? o.css({
            top: -c
        }) : "bottom" == i.attr("openDirection") ? o.css({
            top: d
        }) : c > a ? i.offset().top > c ? o.css({
            top: -c
        }) : 100 > a && i.offset().top > a && i.offset().top > 100 ? o.css({
            top: -c
        }) : o.css({
            top: d
        }) : o.css({
            top: d
        })) : "top" == i.attr("openDirection") ? i.offset().top > o.height() ? o.css({
            top: -o.height()
        }) : (o.height($mainCon.offset().top), o.css({
            top: -$mainCon.offset().top
        })) : "bottom" == i.attr("openDirection") ? a < o.height() ? (o.css({
            top: d
        }), o.height(a)) : o.css({
            top: d
        }) : a < o.height() ? i.offset().top > o.height() ? o.css({
            top: -o.height()
        }) : 100 > a && i.offset().top > a && i.offset().top > 100 ? (o.height(i.offset().top), 
        o.css({
            top: -i.offset().top
        })) : (o.css({
            top: d
        }), o.height(a)) : o.css({
            top: d
        }), i.attr("boxWidth") || o.width() < t + e && o.width(t + e);
    }
    function z(a, b) {
        var c = $("<div></div>");
        return c.attr("id", "selectTree" + selectTree_id + "_container"), c.addClass(a.containerClass), 
        c.attr("hasfocus", 0), c.html(b), c;
    }
    function A(a) {
        var d, b = document.createElement("input"), c = $(b);
        return c.attr("id", "selectTree" + selectTree_id + "_input"), c.attr("type", "text"), 
        c.addClass(a.inputClass), c.attr("autocomplete", "off"), d = !1, null != i.attr("editable") && (d = "true" == i.attr("editable") ? !0 : !1), 
        d ? c.attr("readonly", !1) : c.attr("readonly", "readonly"), ("disabled" == i.attr("disabled") || "true" == i.attr("disabled") || 1 == i.attr("disabled")) && (c.attr("disabled", !0), 
        c.addClass("inputDisabled")), c;
    }
    function B() {
        var b = document.createElement("input"), c = $(b);
        return c.attr("type", "hidden"), null != i.attr("name") && c.attr("name", i.attr("name")), 
        c;
    }
    function C(a, b) {
        return i.attr("relText", a), i.attr("relValue", b), q.val(b), p.val(a), ("true" == w || 1 == w) && (i.attr("editValue", p.val()), 
        q.val(p.val())), i.focus(), !0;
    }
    function D() {
        if (1 == s) if ("" == v) p.val(k), i.attr("relText", k), i.attr("relValue", ""), 
        i.data("selectedNodes", null), q.val(""); else {
            v.split(",");
            var b = "";
            if (b.length > 0 && (b = b.substring(0, b.length - 1)), C(b, v), "false" == i.attr("showInfo") || 0 == i.attr("showInfo")) ; else {
                p.attr("title", b);
                try {
                    addTooltip(p[0]);
                } catch (c) {}
            }
        } else "" == v ? (p.val(k), i.attr("relText", k), i.attr("relValue", ""), i.data("selectedNode", null), 
        q.val("")) : (i.attr("relValue", v), q.val(v));
        1 == w && ("" == v ? i.attr("editValue", k) : i.attr("editValue", i.attr("relText")));
    }
    function E() {
        o.attr("hasfocus", 0), o.hide(), $("body").unbind("mousedown", G), i.trigger("boxClose");
    }
    function F() {
        o.attr("hasfocus", 1), depth++, i.css({
            zIndex: depth
        }), o.show(), i.trigger("boxOpen"), $("body").bind("mousedown", G);
    }
    function G(a) {
        0 == o.attr("hasfocus") || $(a.target).attr("id") == l || $(a.target).attr("id") == m || $(a.target).parents(".selectbox-tree").length > 0 || E();
    }
    var d, e, f, g, h, i, j, k, l, m, o, p, q, r, s, t, u, v, w, c = {};
    c.inputClass = c.inputClass || "selectbox", c.containerClass = c.containerClass || "selectbox-tree", 
    c.hoverClass = c.hoverClass || "current", c.currentClass = c.selectedClass || "selected", 
    c.debug = c.debug || !1, d = 24, e = 24, f = 0, g = 12, h = "宋体", i = $(a), splitMode ? (null != i.attr("selInputHeight") && (d = Number(i.attr("selInputHeight"))), 
    null != i.attr("selButtonWidth") && (e = Number(i.attr("selButtonWidth")))) : (j = $(window.top.document.getElementById("theme")), 
    null != j.attr("selInputHeight") && (d = Number(j.attr("selInputHeight"))), null != j.attr("selButtonWidth") && (e = Number(j.attr("selButtonWidth"))), 
    null != j.attr("defaultSelWidth") && (f = Number(j.attr("defaultSelWidth"))), g = top.getFontSize(), 
    h = top.getFontFamily()), selectTree_id++, k = uncompile(quiLanguage.selectCustom.promptMessage), 
    l = "0_input", m = "0_button", i.addClass("mainCon"), "right" == i.attr("selAlign") && i.css("float", "right"), 
    null != i.attr("prompt") && (k = i.attr("prompt")), o = z(c, b), p = A(c), q = B(c), 
    r = $("<input type='button' value=' ' class='selBtn'/>"), s = !1, null != i.attr("multiMode") && ("true" == i.attr("multiMode") || 1 == i.attr("multiMode") ? (s = !0, 
    r.addClass("selBtnMuiti")) : s = !1), ("disabled" == i.attr("disabled") || "true" == i.attr("disabled") || 1 == i.attr("disabled")) && (r.attr("disabled", !0), 
    1 == s ? r.addClass("selBtn_disabledMuiti") : r.addClass("selBtn_disabled"), p.addClass("selectbox_disabled")), 
    r.attr("id", "selectTree" + selectTree_id + "_button"), t = 99, null != i.attr("selWidth") ? t = Number(i.attr("selWidth")) - e : 0 != f && (t = f - e), 
    p.width(t), p.css("fontFamily", h), p.css("fontSize", g), u = $('<table cellspacing="0" cellpadding="0" style="border-style:none;"><tr><td class="ali01" style="border-style:none;padding:0;margin:0;"></td><td class="ali01" style="border-style:none;;padding:0;margin:0;"></td></tr></table>'), 
    u.find("td").eq(0).append(p), u.find("td").eq(1).append(r), i.append(u), i.append(o), 
    i.append(q), v = "", i.attr("selectedValue") && (v = i.attr("selectedValue")), w = !1, 
    null != i.attr("editable") && (w = "true" == i.attr("editable") ? !0 : !1), o.hide(), 
    D(), w ? (p.css({
        cursor: "text"
    }), p.change(function() {
        i.attr("editValue", $(this).val()), q.val($(this).val());
    })) : (p.css({
        cursor: "pointer"
    }), p.click(function(a) {
        l = $(a.target).attr("id"), x(), depth++, i.css({
            zIndex: depth
        }), 0 == o.attr("hasfocus") ? F() : E();
    })), r.click(function(a) {
        m = $(a.target).attr("id"), x(), depth++, i.css({
            zIndex: depth
        }), 0 == o.attr("hasfocus") ? F() : E();
    });
}, String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};